package com.whc.gulimall.member.web;

import com.alibaba.fastjson.TypeReference;
import com.whc.common.utils.PageUtils;
import com.whc.common.utils.R;
import com.whc.gulimall.member.feign.OrderFeignService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @author angaoen
 */
@Controller
public class WebController {

    @Resource
    private OrderFeignService orderFeignService;

    /**
     * 跳转购买成功后的商品页
     *
     * @param pageNum 页数
     * @param model   视图模型
     * @return 跳转页面
     */
    @GetMapping("/memberOrder.html")
    public String memberOrder(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, Model model) {
        Map<String, Object> map = new HashMap<>(1);
        map.put("page", String.valueOf(pageNum));
        R r = orderFeignService.listOrderItem(map);
        if (Objects.equals(r.getCode(), 0)) {
            model.addAttribute("orderList", r.getData(new TypeReference<PageUtils>() {
            }));
        }
        System.out.println(r.getData(new TypeReference<PageUtils>() {
        }).toString());
        return "orderList";
    }

}
